%clear all; clc;
close all;
%Updated: 05/10/2022

welf0=load('gain_c_state_min_def_yT.txt');    
welf00=load('gain_c_state_min_def_debt.txt');

b2=load('bgrid2.txt');
a2=load('agrid2.txt');

nb=size(b2,1);
na=size(a2,1);

b = welf00(:,1);
b = -b/0.204;
b2=-b2/0.204;

gn = welf00(:,2); 
gn_yT = welf0(:,2);

for i=1:size(gn_yT,1);
    if (gn_yT(i)==100);gn_yT(i)=NaN;end;
end;

[i1,i2]=find(gn>0);
istart=i1(1);
xmin=-0.5;
xmax=1.5;

a = exp(a2);
xmin_yT=0.875;
xmax_yT=1.125;
[i1,i2]=find(gn_yT>0);
istart_yT=i1(1);
ymin_yT=0;
ymax_yT=100;


gNsam=0.1458;
gn = 100*(gn/gNsam-1);
gn_yT = 100*(gn_yT/gNsam-1);


NameArray = {'LineStyle','Color','LineWidth'};
ValueArray1 = {'-';[0.078  0.1686  0.549];2}';
ValueArray2 = {'--','-';[0.078  0.1686  0.549],[0.8  0  0];2,2}';

nameFig = char([char(label_model) '_' char(label_graph) '_aust_debt']);
figure('name',nameFig);
P=plot(b(istart:end),gn(istart:end),'-b','LineWidth',2.5);  xlabel('debt','FontSize',16);ylabel('Difference relative to Samuelson g^N (%)','Fontsize',14)
AX1 = gca;box on;set(AX1,'XTick',xmin:0.5:xmax,'FontSize',16,'XLim',[xmin xmax]);
set(AX1,'YTick',-100:10:-50 ,'YLim',[-100 -50],'FontSize',14);
set(P,NameArray,ValueArray1);grid on;
%saveas(gcf, fullfile(plot_path, nameFig),format_chart);
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);


nameFig = char([char(label_model) '_' char(label_graph) '_aust_yT']);
figure('name',nameFig);
P=plot(a(istart_yT:end),gn_yT(istart_yT:end),'-b','LineWidth',2.5);  xlabel('y^T','FontSize',16);ylabel('Difference relative to Samuelson g^N (%)','Fontsize',14);
AX1 = gca;box on;set(AX1,'XTick',xmin_yT:0.5*(xmax_yT-xmin_yT):xmax_yT,'FontSize',16,'XLim',[xmin_yT xmax_yT]);
set(AX1,'YTick',-100:20:0 ,'YLim',[-100 0],'FontSize',14);
set(P,NameArray,ValueArray1);grid on;
%saveas(gcf, fullfile(plot_path, nameFig),format_chart);
exportfig(gcf, fullfile(plot_path, nameFig),'color','cmyk','resolution',1600);
